package service.edu.controller.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import service.edu.entity.Course;
import service.edu.entity.Teacher;
import service.edu.result.R;
import service.edu.service.CourseService;
import service.edu.service.TeacherService;
import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RequestMapping("/edu/indexTeacher")
@RestController
public class IndexTeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;

    @ApiOperation("首页教师分页查询")
    @GetMapping("/pageQuery/{current}/{limit}")
    public R pageQuery(@ApiParam(name = "current", value = "当前页码", required = true)
                       @PathVariable("current")long current,
                       @ApiParam(name = "limit", value = "每页记录数", required = true)
                       @PathVariable("limit")long limit){
        Page<Teacher> page = new Page<>(current,limit);
        HashMap<String,Object> map=teacherService.getIndexTeacherList(page);
        return R.Ok().data(map);
    }

    @ApiOperation("根据舰娘id查询舰娘信息与对应课程信息")
    @GetMapping("/queryInfo/{teacherId}")
    public R getTeacherInfoById(@PathVariable long teacherId){
        Teacher teacher = teacherService.getById(teacherId);
        //根据舰娘id查询对应课程信息
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        wrapper.orderByDesc("gmt_modified");
        List<Course> courseList = courseService.list(wrapper);
        return R.Ok().data("jianniang",teacher).data("courseList", courseList);
    }

}
